package inventory.view;

import inventory.controler.CategoryManagementControler;
import inventory.controler.MaterialManagementController;
import inventory.model.CategoryMaster;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.SpringLayout;

public class InventoryDriverHelper implements ActionListener
{
	private InventoryDriver ind;
	
	public InventoryDriverHelper() 
	{
		super();
	}

	public InventoryDriverHelper(InventoryDriver ind) 
	{
		super();
		this.ind = ind;
		ind.addListeners(this);
	}

	private void addPanel(JPanel panel,JPanel parentPanel,JSeparator sep)
	{
		if(parentPanel.getComponentCount()==4)
			parentPanel.remove(3);
		
		SpringLayout lay=(SpringLayout) parentPanel.getLayout();
		lay.putConstraint(SpringLayout.NORTH, panel, 10, SpringLayout.NORTH, parentPanel);
		lay.putConstraint(SpringLayout.WEST, panel, 6, SpringLayout.EAST, sep);
		lay.putConstraint(SpringLayout.SOUTH, panel, 0, SpringLayout.SOUTH, sep);
		lay.putConstraint(SpringLayout.EAST, panel, -10,SpringLayout.EAST,parentPanel);
		parentPanel.add(panel);
		
		parentPanel.revalidate();
		parentPanel.repaint();
	}
	
	@Override
	public void actionPerformed(ActionEvent e) 
	{
		String k=e.getActionCommand().toString();
		if(k.contains("category"))
		{
			CategoryManagement cm=new CategoryManagement();
			
			addPanel(cm,ind.getPanelMasterManagment(),ind.getSeparator_2());
			
			CategoryManagementControler cmc=new CategoryManagementControler(null,cm);
		}
		if(k.contains("material"))
		{
			MaterialManagement mm=new MaterialManagement();
			
			addPanel(mm,ind.getPanelMasterManagment(),ind.getSeparator_2());
			
			MaterialManagementController mmc=new MaterialManagementController(mm, null);	
		}
	}

	public InventoryDriver getInd() {
		return ind;
	}

	public void setInd(InventoryDriver ind) {
		this.ind = ind;
	}
	
}
